package demo3;

import java.util.Scanner;

public class Practise5 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int rows = in.nextInt();
        int cols = in.nextInt();
        int[][] ret = new int[rows][cols];
        int[][] high = new int[rows][cols];//最低高度
        int k = in.nextInt();
        int totalCount = rows * cols;
        for (int i = 0; i < k && totalCount != 0; i++) {
            int row = in.nextInt() - 1;
            int col = in.nextInt() - 1;
            int h = in.nextInt();
            int color = in.nextInt();
            if(h < high[row][col] || high[row][col] == 0) {
                if(h == 1) {
                    totalCount--;
                }
                high[row][col] = h;
                ret[row][col] = color;
            }
        }
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                System.out.printf("%d ", ret[i][j]);
            }
            System.out.println();
        }
    }
}
